模板代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2+5;
int data[maxn];
struct node{
int v,height;
node *lchild, *rchild;
};
node* newNode(int v){
node* Node = new node;
Node->v = v;
Node->height = 1;
Node->lchild = Node->rchild = NULL;
return Node;
}
int getHeight(node *root){
if (root == NULL) return 0;
else return root->height;
}
int getBlanceFactor(node* root){
return getHeight(root->lchild) - getHeight(root->rchild);
}
void upDateHeight(node *root){
root->height = max(root->lchild->height, root->rchild->height) + 1;
return ;
}
void search_v(node *root, int v){
if (root == NULL){
printf("search failed!!\n");
return;
}
if (v == root->v){
cout<<v<<endl;
}
else if (v < root